import CryptoJS from "crypto-js";
import {AESKey} from './global';

const key = CryptoJS.enc.Utf8.parse(AESKey.key)

export const crypto = {
    /**
     * AES加密 ：字符串 key iv  返回base64
     */

    Encrypt: function (word) {
        let srcs = CryptoJS.enc.Utf8.parse(word);
        let encrypted = CryptoJS.AES.encrypt(srcs, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
        return encrypted.toString();
    },
    /**
     * AES 解密 ：字符串 key iv  返回base64
     *
     */
    Decrypt: function (word) {
        let decrypt = CryptoJS.AES.decrypt(word,key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
        let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
    }
}

export default {
    crypto
}